In [ ]:
%autosave 0
In [ ]:
x = dict() # Create empty dictionary
x[0] = 'abc' # Create
x[0] = 'xyz' # update
print(x[0])
print(x[1]) # No item... error
In [ ]:
# Dicationary which value is List
# Disctionary is enclosed with brace {}
x = {'a': ['apple', 'anaconda'], 'b': ['beatles', 'beethoven']}
x['b'].append('beegees')
print(x)
In [ ]:
# MCPC rehearsal problem 1
s1 = "Living John Piano"
s2 = "Bath Alice Toothbrush"
who_what_dict = dict() # Key Where, Value (Who, What)
x = s1.split()
who_what_dict[x[0]] = x[1:]
x = s2.split()
who_what_dict[x[0]] = x[1:]
# What is in Living ?
print(who_what_dict['Living'][1]) # [0]: Who, [1]: What
In [ ]:
list_x = [1, 1, 2, 2, 3, 3, 4]
set_x = set(list_x)
print(set_x)
str_x = 'this is a string'
set_x = set(str_x)
print(set_x)
print(set_x[0]) # error
In [ ]:
set_a = {1, 2, 3, 4}
set_b = {3, 4, 5, 6}
print(set_a & set_b)
print(set_a | set_b)
print(set_a ^ set_b)
print(set_a - set_b)
In [ ]:
set_a = {1, 2, 3, 4}
set_b = {3, 4}
set_c = {3, 4}
print (set_a > set_b) # is set_a a superset of set_b ?
print (set_b > set_a)
print (set_b < set_a)
print (set_b >= set_c)
print (set_b > set_c)